﻿@using System.Net.Http
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.JSInterop
@using Microsoft.AspNetCore.Components
@using Microsoft.AspNetCore.Components.Web;
@using System.Security.Claims;
@using System.Threading.Tasks;
@using Microsoft.AspNetCore.Components.Authorization;
@using WebVella.Erp.Api.Models;
@*@using BlazorComponentUtilities; // nice new CssBuilder lib*@ 

@inject IJSRuntime JSRuntime;

@if (!Rendered)
{
	<div class="go-red">Loading</div>
}
else if (User == null)
{
	<div class="go-orange">Not logged</div>
}
else
{
	<h3>HelloWorld @Dates.Count @User.Email</h3>
	<wv-button></wv-button>
	<button @onclick="AddDate">Add Date</button>
	@foreach (var date in Dates)
	{
		@date
	}
}


@code {
	[Parameter(CaptureUnmatchedValues = true)]
	public Dictionary<string, object> InputAttributes { get; set; } =
	  new Dictionary<string, object>()
			{
					{ "id", "DefaultId" },
					{ "type", "text" },
					{ "placeholder", "" },
					{ "class", "" }
						};

	[Parameter]
	public RenderFragment ChildContent { get; set; }

	[Parameter]
	public ErpUser User { get; set; }

	protected bool Rendered = false;



	public List<string> Dates { get; set; } = new List<string>();

	protected override void OnInitialized()
	{
		for (int i = 0; i < 1; i++)
		{
			Dates.Add(DateTime.Now.ToString());
		}
	}

	protected override void OnAfterRender(bool firstRender)
	{
		if (firstRender)
		{
			Rendered = true;
			StateHasChanged();
		}
	}


	private async Task AddDate()
	{

		await JSRuntime.InvokeVoidAsync("handleTickerChanged", Dates.Count);
		Dates.Insert(0, DateTime.Now.ToString());
	}
}